<template>
  <div class="index-task-item" @tap="onSelect">
    <div class="index-task-item__header">
      <span class="index-task-item__header-dot" />
      <span>{{ (data && data.name) || "--" }}</span>
    </div>
    <div class="index-task-item__content">
      <CommonProgress
        :percentage="((data && data.completedPercent) || 0) * 100"
      />
      <div class="index-task-item__content-tag">
        <span>
          {{ (data && data.completedCount) || 0 }}/{{
            (data && data.targetCount) || 0
          }}条
          {{ (data && data.name) || "" }}
        </span>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "index-task-item",
};
</script>

<script setup lang="ts">
import { IMissionItemRes } from "@/apis/types/home";
import CommonProgress from "@/components/common-progress/index.vue";
import Taro from "@tarojs/taro";

import { DUCUMENT_CATEGORY_ID } from "@/constants/index";

const props = withDefaults(
  defineProps<{
    data: IMissionItemRes | null;
  }>(),
  {
    data: null,
  }
);

const onSelect = () => {
  const { data } = props;
  if (!data) return;
  const { actionRelatedData } = data;
  Taro.setStorageSync(DUCUMENT_CATEGORY_ID, actionRelatedData);
  Taro.switchTab({
    url: `/pages/document/index`,
  });
};
</script>

<style lang="less">
.index-task-item {
  width: 50%;
  background-color: white;
  border-radius: 20px;
  padding: 16px;
  box-sizing: border-box;
  &__header {
    font-weight: 500;
    font-size: 28px;
    color: #000000;
    line-height: 40px;
    display: flex;
    align-items: center;
    gap: 12px;
    &-dot {
      width: 4px;
      height: 18px;
      background-color: #7ed6c6;
      border-radius: 2px;
    }
  }
  &__content {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    &-tag {
      display: flex;
      justify-content: flex-end;
      align-items: center;

      font-weight: 400;
      font-size: 22px;
      color: #898989;
      line-height: 34px;
    }
  }
}
</style>
